package com.lxg.demo.controller;

import com.lxg.demo.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    private HelloService helloService;

    @GetMapping("/hello")
    public String sayHello(@RequestParam(value = "name", defaultValue = "World") String name,
                           @RequestParam(value = "status") String status) {
        boolean validFlag = helloService.isValidUser(name);
        if(!validFlag){
            return "非法用户，没有登录权限！！";
        }
        boolean loginFlag = helloService.isLogin(status);
        if(!loginFlag){
            return "用户未登录，请登录后在尝试！";
        }
        return helloService.greet(name);
    }

    @GetMapping("/login")
    public String login(@RequestParam(value = "name", defaultValue = "name") String name,
                           @RequestParam(value = "pwd") String pwd) {
        boolean loginFlag = helloService.login(name, pwd);
        if(!loginFlag){
            return "用户登录失败？！请输入name#pwd";
        }
        return "用户登录成功！！";
    }
}
